package com.stylefeng.guns.modular.map.controller;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.area.dao.BdapAreaLoyaltyMmMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaPopPropDmMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaPopPropDtMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaPopPropHmMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaPopPropQmMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaStayMmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubAreaMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaLoyaltyMmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaPopPropDmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaPopPropDtMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaPopPropHmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaPopPropQmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubareaStayMmMapper;
import com.stylefeng.guns.modular.area.model.BdapArea;
import com.stylefeng.guns.modular.area.model.BdapAreaLoyaltyMm;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropDm;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropDt;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropHm;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropQm;
import com.stylefeng.guns.modular.area.model.BdapAreaStayMm;
import com.stylefeng.guns.modular.area.model.BdapSubArea;
import com.stylefeng.guns.modular.area.model.BdapSubareaLoyaltyMm;
import com.stylefeng.guns.modular.area.model.BdapSubareaPopPropDm;
import com.stylefeng.guns.modular.area.model.BdapSubareaPopPropDt;
import com.stylefeng.guns.modular.area.model.BdapSubareaPopPropHm;
import com.stylefeng.guns.modular.area.model.BdapSubareaPopPropQm;
import com.stylefeng.guns.modular.area.model.BdapSubareaStayMm;
import com.stylefeng.guns.modular.area.util.AreaUtil;
import com.stylefeng.guns.modular.map.dao.BdapCellLoyaltyMmMapper;
import com.stylefeng.guns.modular.map.dao.BdapCellStayDmMapper;
import com.stylefeng.guns.modular.map.dao.BdapCellStayMmMapper;
import com.stylefeng.guns.modular.map.dao.TraceDayMapper;
import com.stylefeng.guns.modular.map.dao.TraceHourMapper;
import com.stylefeng.guns.modular.map.dao.TraceMonthMapper;
import com.stylefeng.guns.modular.map.model.AgeSegmentation;
import com.stylefeng.guns.modular.map.model.AreaDmModel;
import com.stylefeng.guns.modular.map.model.AreaDtModel;
import com.stylefeng.guns.modular.map.model.AreaHmModel;
import com.stylefeng.guns.modular.map.model.BdapCellLoyaltyMm;
import com.stylefeng.guns.modular.map.model.BdapCellStayDm;
import com.stylefeng.guns.modular.map.model.BdapCellStayMm;
import com.stylefeng.guns.modular.map.model.Consumption;
import com.stylefeng.guns.modular.map.model.CumulativePassenger;
import com.stylefeng.guns.modular.map.model.LoyaltySituation;
import com.stylefeng.guns.modular.map.model.MyTimeType;
import com.stylefeng.guns.modular.map.model.OriginPopulation;
import com.stylefeng.guns.modular.map.model.PassengerFlowUtil;
import com.stylefeng.guns.modular.map.model.PassingDensity;
import com.stylefeng.guns.modular.map.model.PassingPopulation;
import com.stylefeng.guns.modular.map.model.PermanentPeople;
import com.stylefeng.guns.modular.map.model.RealPassenger;
import com.stylefeng.guns.modular.map.model.Sex;
import com.stylefeng.guns.modular.map.model.StaySituation;
import com.stylefeng.guns.modular.map.model.StayTimeRanking;
import com.stylefeng.guns.modular.map.model.SubAreaDmModel;
import com.stylefeng.guns.modular.map.model.SubAreaDtModel;
import com.stylefeng.guns.modular.map.model.SubAreaHmModel;
import com.stylefeng.guns.modular.map.model.TerminalPopulation;
import com.stylefeng.guns.modular.map.model.TraceDay;
import com.stylefeng.guns.modular.map.model.TraceHour;
import com.stylefeng.guns.modular.map.model.TraceMonth;
import com.stylefeng.guns.modular.map.model.TravelPopulation;
import com.stylefeng.guns.modular.map.model.WorkForce;
import com.stylefeng.guns.modular.util.ExcleExportUtil;
import com.stylefeng.guns.modular.util.MySplitUtilToList;
import com.stylefeng.guns.modular.util.StringUtil;
import com.stylefeng.guns.modular.util.TimeUtil;
/**
 * 图表数据导出
 * ClassName: ScreenExportController 
 * @Description: TODO
 * @author zhangyaoyao
 * @date 2018年3月1日
 */
@Controller
@RequestMapping("/screenExport")
public class ScreenExportController extends BaseController{
	@Autowired
	private TraceDayMapper traceDayMapper;
	@Autowired
	BdapAreaMapper areaMapper;
	@Autowired
	BdapSubAreaMapper subareaMapper;
	@Autowired
	private TraceMonthMapper traceMonthMapper;
	@Autowired
	private BdapCellStayDmMapper bdapCellStayDmMaper;
	@Autowired
	private BdapCellStayMmMapper bdapCellStayMmMaper;
	@Autowired
	private BdapCellLoyaltyMmMapper bdapCellLoyaltyMmMapper;
	@Autowired
    private TraceHourMapper traceHourMapper;
	@Autowired
	private BdapAreaPopPropQmMapper areaQmMapper;
	@Autowired
	private BdapAreaPopPropHmMapper areaHmMapper;
	@Autowired
	private BdapSubareaPopPropQmMapper subAreaQmMapper;
	@Autowired
	private BdapSubareaPopPropHmMapper subAreaHmMapper;
	@Autowired
	private BdapSubareaPopPropDmMapper subAreaDmMapper;
	@Autowired
	private BdapAreaPopPropDmMapper areaDmMapper;
	@Autowired
	private BdapAreaPopPropDtMapper areaDtMapper;
	@Autowired
	private BdapSubareaPopPropDtMapper subAreaDtMapper;
	@Autowired
	private BdapAreaStayMmMapper areaStayMmMapper;
	@Autowired
	private BdapSubareaStayMmMapper subAreaStayMmMapper;
	@Autowired
	private BdapAreaLoyaltyMmMapper areaLoyaltyMapper;
	@Autowired
	private BdapSubareaLoyaltyMmMapper subAreaLoyaltyMapper;
	
	/**
	 * 实时客流导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月6日
	 */
	@RequestMapping(value = "/realPassengerExport")
    @ResponseBody
    public void realPassenger(String beginTime,String timeType,String peopleType,String areaId,String subAreaId,String areaname,HttpServletRequest request,HttpServletResponse response) {
		if (ToolUtil.isEmpty(beginTime) || ToolUtil.isEmpty(timeType)) {
			return;
		}
		RealPassenger realPassenger = new RealPassenger();
		Map<String, String> userTotalMap = new LinkedHashMap<>();// 存放实时客流数据<时间，人数>
		Map<String, String> ForcastUserTotalMap = new LinkedHashMap<>();// 存放预测客流数据<时间，人数>
		// List<String> userTime = new ArrayList<String>(); //存放实时客流对应的时间
		Set<String> userTime = new TreeSet<String>(); // 存放实时客流对应的时间
		List<String> timeString = new ArrayList<>();// 存放一天的所有时间集合（小时：00,01,02……）
		List<String> minute = new ArrayList<String>();
		minute.add("00");
		minute.add("15");
		minute.add("30");
		minute.add("45");
		String maximum = null;// 查询出的当天最大时间
		List<String> maximumList = new ArrayList<String>();
		if(timeType.equals("分钟")){
			for(int i=0;i<=23;i++){
				String string  = null;
				if(i<10){
					String str = "0";
					string = str + i;
					for(int j=0;j<minute.size();j++){
						String time = string + minute.get(j);
						timeString.add(time);
					}
				}
				if(i>=10){
					String valueOf = String.valueOf(i);
					for(int j=0;j<minute.size();j++){
						String time = valueOf + minute.get(j);
						timeString.add(time);
					}
				}
			}
		}else{
			for (int i = 0; i <= 23; i++) {
				String string = null;
				if (i < 10) {
					String str = "0";
					string = str + i;
					timeString.add(string);
				}
				if (i >= 10) {
					String valueOf = String.valueOf(i);
					timeString.add(valueOf);
				}
			}
		}
		MyTimeType mytimeType = new MyTimeType();
		// 1.根据时间和区域id去区域表查询警戒值，饱和值，警戒值
		// 2.封装到实时客流（类）里面对应的list集合中
		if (ToolUtil.isEmpty(subAreaId)) {
			BdapArea area = areaMapper.selectById(Long.parseLong(areaId));
			if (ToolUtil.isEmpty(area)) {
				return;
			}
			realPassenger.getRealWarningValue().add(area.getWarningValue());
			realPassenger.getRealSaturationValue().add(area.getSaturationValue());
			realPassenger.getRealServerValue().add(area.getSevereValue());
		} else {
			BdapSubArea subarea = subareaMapper.selectById(Long.parseLong(subAreaId));
			if (ToolUtil.isEmpty(subarea)) {
				return;
			}
			realPassenger.getRealWarningValue().add(subarea.getWarningValue());
			realPassenger.getRealSaturationValue().add(subarea.getSaturationValue());
			realPassenger.getRealServerValue().add(subarea.getSevereValue());
		}
		Date date = new Date();
		SimpleDateFormat formatHour = null;
		String hour = null;
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		if(timeType.equals("分钟")){
			formatHour = new SimpleDateFormat("HH:mm");
			hour = formatHour.format(date);// 当前时间
			String substringHour = hour.substring(0,2);
			String substringMinute = hour.substring(3,5);
			int parseInt = Integer.parseInt(substringMinute);
			if(parseInt<=15){
				parseInt = 0;
			}else if(15<parseInt&&parseInt<=30){
				parseInt = 15;
			}else if(30<parseInt&&parseInt<=45){
				parseInt = 30;
			}else if(parseInt>45){
				parseInt = 45;
			}
			if(parseInt<=10){
				hour = substringHour + "0" + String.valueOf(parseInt);
			}else{
				hour = substringHour + String.valueOf(parseInt);
			}
		}else{
			formatHour = new SimpleDateFormat("HH");
			hour = formatHour.format(date);
		}
		String formatTime = format.format(date);
		String replaceTime = beginTime.replace("-", "");
		mytimeType.setBeginTime(replaceTime);
		mytimeType.setUpTime(replaceTime);
		if(ToolUtil.isNotEmpty(subAreaId)){
			mytimeType.setSubAreaId(subAreaId);
			if(timeType.equals("分钟")){
				List<BdapSubareaPopPropQm> SubareaQmList = subAreaQmMapper.selectSubAreaPopulationByTime(mytimeType);
				for (BdapSubareaPopPropQm bdapSubareaPopPropQm : SubareaQmList) {
					String totalUsers = bdapSubareaPopPropQm.getTotalUsers();
					String statMinute = bdapSubareaPopPropQm.getStatMinutes();
					statMinute = statMinute.substring(8);
					String prefixMinute = statMinute.substring(0, 2);
					String postfixMinute = statMinute.substring(2, 4);
					userTotalMap.put(statMinute, totalUsers);// 实时客流map
					ForcastUserTotalMap.put(statMinute, "-");// 预测客流map
					String stringHour = prefixMinute + ":" + postfixMinute;
					userTime.add(stringHour);// 时间
					maximumList.add(statMinute);
				}
			}else{
				List<BdapSubareaPopPropHm> areaHmList = subAreaHmMapper.selectSubAreaHourPopulation(mytimeType);
				for (BdapSubareaPopPropHm bdapSubareaPopPropHm : areaHmList) {
					String totalUsers = bdapSubareaPopPropHm.getTotalUsers();
					String statHour = bdapSubareaPopPropHm.getStatHour();
					String substringHour = statHour.substring(8);
					userTotalMap.put(substringHour, totalUsers);// 实时客流map
					ForcastUserTotalMap.put(substringHour, "-");// 预测客流map
					String stringHour = substringHour + ":00";
					userTime.add(stringHour);// 时间
					maximumList.add(substringHour);
				}
			}
		}else{
			mytimeType.setAreaId(areaId);
			if(timeType.equals("分钟")){
				List<BdapAreaPopPropQm> areaMinnuteList = areaQmMapper.selectAreaMinnutePopuplation(mytimeType);
				for (BdapAreaPopPropQm bdapAreaPopPropQm : areaMinnuteList) {
					String totalUsers = bdapAreaPopPropQm.getTotalUsers();
					String statMinute = bdapAreaPopPropQm.getStatMinutes();
					statMinute = statMinute.substring(8);
					String prefixMinute = statMinute.substring(0, 2);
					String postfixMinute = statMinute.substring(2, 4);
					userTotalMap.put(statMinute, totalUsers);// 实时客流map
					ForcastUserTotalMap.put(statMinute, "-");// 预测客流map
					String stringHour = prefixMinute + ":" + postfixMinute;
					userTime.add(stringHour);// 时间
					maximumList.add(statMinute);
				}
			}else{
				List<BdapAreaPopPropHm> areaHourList = areaHmMapper.selectAreaHourPopulation(mytimeType);
				for (BdapAreaPopPropHm bdapAreaPopPropHm : areaHourList) {
					String totalUsers = bdapAreaPopPropHm.getTotalUsers();
					String statHour = bdapAreaPopPropHm.getStatHour();
					String substringHour = statHour.substring(8);
					userTotalMap.put(substringHour, totalUsers);// 实时客流map
					ForcastUserTotalMap.put(substringHour, "-");// 预测客流map
					String stringHour = substringHour + ":00";
					userTime.add(stringHour);// 时间
					maximumList.add(substringHour);
				}
			}
		}
		Collections.sort(maximumList);
		if (maximumList.size() > 0) {
			maximum = maximumList.get(maximumList.size() - 1);
		} else {
			maximum = hour;
		}
		int maximumInt = Integer.parseInt(maximum);
		for (int i = 0; i < timeString.size(); i++) {
			String key = timeString.get(i);
			int keyInt = Integer.parseInt(key);
			if (userTotalMap.containsKey(key)) {
				continue;
			} else {
				if (keyInt <= maximumInt) {
					userTotalMap.put(key, "0");
				}
			}
		}
		String realPassengerNow = null;// 当前时间实时客流人数
		String realPassengerBefore = null;// 上一小时的实时客流人数
		// Integer beforeHour = Integer.parseInt(hour) - 1;
		Integer beforeHour = Integer.parseInt(maximum) - 1;
		String beforeString = null;
		String nextHour = null;
		if(timeType.equals("分钟")){
			String beforeFifiteen = null;
			String nextFifteen = null;
			String substringMinute = maximum.substring(2,4);
			String substringHour = maximum.substring(0,2);
			int parseIntMinute = Integer.parseInt(substringMinute);
			int parseIntHour = Integer.parseInt(substringHour);
			int beforeFifteenMinute = 0;
			int beforeFifteenHour = 0;
			int nextFifteenMinute = 0;
			int nextFifteenHour = 0;
			if(parseIntMinute==0){
				beforeFifteenMinute = 45;
				nextFifteenMinute = parseIntMinute + 15;
				if(parseIntHour==0){
					beforeFifteenHour = 23;
				}else{
					beforeFifteenHour = parseIntHour - 1;
				}
				nextFifteenHour = parseIntHour;
			}else{
				beforeFifteenMinute = parseIntMinute-15;
				nextFifteenMinute = parseIntMinute + 15;
				if(beforeFifteenMinute<0){
					beforeFifteenHour = parseIntHour - 1;
				}else{
					beforeFifteenHour = parseIntHour;
				}
				if(nextFifteenMinute==60){
					nextFifteenHour = parseIntHour + 1;
				}else{
					nextFifteenHour = parseIntHour;
				}
				if(nextFifteenHour==24){
					nextFifteenHour = 0;
				}
			}
			if(parseIntHour<10){
				if(beforeFifteenMinute==0){
					beforeFifiteen ="0" + String.valueOf(beforeFifteenHour) + beforeFifteenMinute + "0";
				}else if(parseIntHour==0&&beforeFifteenHour!=0){
					beforeFifiteen =String.valueOf(beforeFifteenHour) + beforeFifteenMinute;
				}else{
					beforeFifiteen ="0" + String.valueOf(beforeFifteenHour) + beforeFifteenMinute;
				}
			}else if(parseIntHour==10&&beforeFifteenHour<10){
				beforeFifiteen ="0" + String.valueOf(beforeFifteenHour) + beforeFifteenMinute;
			}else if(beforeFifteenMinute==0){
				beforeFifiteen = String.valueOf(beforeFifteenHour) + beforeFifteenMinute + "0";
			}else{
				beforeFifiteen = String.valueOf(beforeFifteenHour) + beforeFifteenMinute;
			}
			if(nextFifteenHour<10){
				if(nextFifteenMinute==60){
					nextFifteenMinute = 0;
					nextFifteen ="0" + String.valueOf(nextFifteenHour) + nextFifteenMinute + "0";
				}else{
					nextFifteen ="0" + String.valueOf(nextFifteenHour) + nextFifteenMinute;
				}
			}else{
				if(nextFifteenMinute==60){
					nextFifteenMinute = 0;
					nextFifteen = String.valueOf(nextFifteenHour) + nextFifteenMinute + "0";
				}else{
					nextFifteen = String.valueOf(nextFifteenHour) + nextFifteenMinute;
				}
			}
			System.out.println("beforeFifteen==="+beforeFifiteen);
			System.out.println("nextFifteen==="+nextFifteen);
			beforeString = beforeFifiteen;
			nextHour = nextFifteen;
		}
		if(timeType.equals("小时")){
			if (beforeHour < 10) {
				beforeString = "0" + String.valueOf(beforeHour);// 上一小时
			} else {
				beforeString = String.valueOf(beforeHour);// 上一小时
			}
			// Integer hourToInt = Integer.parseInt(hour);
			Integer hourToInt = Integer.parseInt(maximum);
			hourToInt = hourToInt + 1;
			if (hourToInt < 10) {
				nextHour = "0" + String.valueOf(hourToInt);// 预测下一小时的时间
			} else {
				nextHour = String.valueOf(hourToInt);// 预测下一小时的时间
			}
			if (nextHour.equals("24")) {// 预测下一小时的时间若为24点，则改为00
				nextHour = "00";
			}
			if (hour.equals("00")) {
				nextHour = "0" + Integer.valueOf(hourToInt);// 当前时间若为00点，则下一小时为01
			}
		}
		String nextPassengerUc = null;
		if (userTotalMap.size() > 0 && formatTime.equals(beginTime)) {
			// if(userTotalMap.containsKey(hour)){
			// realPassengerNow = userTotalMap.get(hour);//当前实时客流人数
			realPassengerNow = userTotalMap.get(maximum);// 当前实时客流人数
			realPassengerBefore = userTotalMap.get(beforeString);// 前一小时实时客流人数
			if(ToolUtil.isNotEmpty(subAreaId)){
				if(timeType.equals("分钟")){
					BdapSubareaPopPropQm subAreaQmBefore = new BdapSubareaPopPropQm();
					BdapSubareaPopPropQm subAreaQmNow = new BdapSubareaPopPropQm();
					subAreaQmBefore.setTotalUsers(realPassengerBefore);
					subAreaQmNow.setTotalUsers(realPassengerNow);
					nextPassengerUc = PassengerFlowUtil.getSubAreaNextFifteenUc(subAreaQmNow, subAreaQmBefore);
				}else{
					BdapSubareaPopPropHm subAreaHmBefore = new BdapSubareaPopPropHm();
					BdapSubareaPopPropHm subAreaHmNow = new BdapSubareaPopPropHm();
					subAreaHmBefore.setTotalUsers(realPassengerBefore);
					subAreaHmNow.setTotalUsers(realPassengerNow);
					nextPassengerUc = PassengerFlowUtil.getSubAreaNextHourUc(subAreaHmNow, subAreaHmBefore);
				}
			}else{
				if(timeType.equals("分钟")){
					BdapAreaPopPropQm areaQmBefore = new BdapAreaPopPropQm();
					BdapAreaPopPropQm areaQmNow = new BdapAreaPopPropQm();
					areaQmBefore.setTotalUsers(realPassengerBefore);
					areaQmNow.setTotalUsers(realPassengerNow);
					nextPassengerUc = PassengerFlowUtil.getAreaNextFifteenUc(areaQmNow, areaQmBefore);
				}else{
					BdapAreaPopPropHm before = new BdapAreaPopPropHm();
					BdapAreaPopPropHm now = new BdapAreaPopPropHm();
					before.setTotalUsers(realPassengerBefore);
					now.setTotalUsers(realPassengerNow);
					nextPassengerUc = PassengerFlowUtil.getAreaNextHourUc(now, before);
				}
			}
//			before.setTotalUsers(realPassengerBefore);
//			now.setTotalUsers(realPassengerNow);
//			String nextHourUc = AreaUtil.getNextHourUc(now, before);// 预测的下一小时客流人数
			// ForcastUserTotalMap.put(hour,
			// realPassengerNow);//将当前时间客流添加进预测客流map中
			ForcastUserTotalMap.put(maximum, realPassengerNow);// 将当前时间客流添加进预测客流map中
			ForcastUserTotalMap.put(nextHour, nextPassengerUc);// 将预测的下一小时客流人数添加进预测客流map中
//			ForcastUserTotalMap.put(nextHour, nextHourUc);// 将预测的下一小时客流人数添加进预测客流map中
			if(timeType.equals("小时")){
				nextHour = nextHour + ":00";
			}else{
				String substringMinute = nextHour.substring(2,4);
				String substringHour = nextHour.substring(0,2);
				nextHour = substringHour + ":" +substringMinute;
			}
			for (int j = 0; j < timeString.size(); j++) {
				String str = timeString.get(j);
				String t = null;
				if(timeType.equals("小时")){
					t = str + ":00";
				}else{
					String substringMinute = str.substring(2,4);
					String substringHour = str.substring(0,2);
					t = substringHour + ":" +substringMinute;
				}
				userTime.add(t);
				// if(hour.equals(str)){
				if (maximum.equals(str)) {
					break;
				}
			}
			if (formatTime.equals(beginTime) && userTime.size() > 0) {
				userTime.add(nextHour);// 如果查询的是当天时间,则将预测时间添加进时间集合（折线图x轴）
			}
		}
		List<String> userTotalMapKey = new ArrayList<>();
		// 遍历实时客流map的key值，添加进集合中
		for (Entry<String, String> entry : userTotalMap.entrySet()) {
			String key = entry.getKey();
			userTotalMapKey.add(key);
		}
		// 对实时客流map的key值（时间）进行排序,变成00,01,02……，添加进集合中
		Collections.sort(userTotalMapKey);
		// 遍历排序后的集合，如果查询的是当天时间的实时客流，则将实时客流人数添加到realPassenger的实时客流集合中
		for (int i = 0; i < userTotalMapKey.size(); i++) {
			String key = userTotalMapKey.get(i);
			String value = userTotalMap.get(key);
			if (formatTime.equals(beginTime)) {

				realPassenger.getRealAllPerson().add(value);
				// hour：当前时间（小时）
				// if(hour.equals(key)){
				if (maximum.equals(key)) {
					realPassenger.getRealAllPerson().add("-");
					break;
				}
				ForcastUserTotalMap.put(key, "-");
			} else {
				realPassenger.getRealAllPerson().add(value);
			}
		}
		List<String> ForcastMapKey = new ArrayList<>();
		// 遍历预测客流map的key值，添加进集合中
		for (Entry<String, String> entry : ForcastUserTotalMap.entrySet()) {
			String key = entry.getKey();
			ForcastMapKey.add(key);
		}
		// 对预测客流map的key值（时间）进行排序,变成00,01,02……，添加进集合中
		Collections.sort(ForcastMapKey);
		// 遍历排序后的集合，如果查询的是当天时间的实时客流，则将预测客流人数添加到realPassenger的预测客流集合中
		for (int i = 0; i < ForcastMapKey.size(); i++) {
			String key = ForcastMapKey.get(i);
			String value = ForcastUserTotalMap.get(key);
			if (formatTime.equals(beginTime)) {
				realPassenger.getRealFluidPerson().add(value);
			}
		}
		for (String str : userTime) {
			realPassenger.getRealPassengerTimes().add(str);
			if (nextHour.equals(str) && formatTime.equals(beginTime)) {
				break;
			}
		}
    	String areaName = areaname;
		Integer warningValue = 0;
		Integer saturationValue = 0;
		Integer serverValue = 0;
		String[] rowsName = null;
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "实时客流";
    	List<String> realAllPersonList = realPassenger.getRealAllPerson();
    	List<String> realFluidPersonList = realPassenger.getRealFluidPerson();
    	List<String> realPassengerTimeList = realPassenger.getRealPassengerTimes();
		if(formatTime.equals(beginTime)){
			rowsName = new String[] { "区域", "日期", "时间", "客流(所有人口)", "客流预测(流动人口)", "饱和值", "警戒值", "严重值" };
			for(int i=0;i<realPassengerTimeList.size();i++){
	    		Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = beginTime;
				objs[2] = realPassengerTimeList.get(i);
				objs[3] = realAllPersonList.get(i);
				objs[4] = realFluidPersonList.get(i);
				objs[5] = realPassenger.getRealSaturationValue();
				objs[6] = realPassenger.getRealWarningValue();
				objs[7] = realPassenger.getRealServerValue();
				dataList.add(objs);
	    	}
		}else{
			rowsName = new String[] { "区域", "日期", "时间", "客流(所有人口)", "饱和值", "警戒值", "严重值" };
			for(int i=0;i<realAllPersonList.size();i++){
	    		Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = beginTime;
				objs[2] = realPassengerTimeList.get(i);
				objs[3] = realAllPersonList.get(i);
				objs[4] = realPassenger.getRealSaturationValue();
				objs[5] = realPassenger.getRealWarningValue();
				objs[6] = realPassenger.getRealServerValue();
				dataList.add(objs);
	    	}
		}
		
    	
    	ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }
	/**
	 * 峰值客流导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param timeType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param areaname
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/peakPassengerExport")
	@ResponseBody
	public void peakPassengerExport(String beginTime, @RequestParam(required = false) String upTime, String timeType,
			String areaId, String subAreaId, String areaname, HttpServletRequest request,
			HttpServletResponse response) {
		if (ToolUtil.isEmpty(beginTime) || ToolUtil.isEmpty(timeType)) {
			return;
		}
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		String areaName = areaname;
		Integer warningValue = 0;
		Integer saturationValue = 0;
		Integer serverValue = 0;
		String[] rowsName = new String[] { "区域", "时间", "峰值客流(所有人口)", "峰值客流(流动人口)", "饱和值", "警戒值", "严重值" };
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "峰值客流";
		if (ToolUtil.isEmpty(subAreaId)) {
			BdapArea area = areaMapper.selectById(Long.parseLong(areaId));
			if (ToolUtil.isEmpty(area)) {
				return;
			}
			warningValue = area.getWarningValue();
			saturationValue = area.getSaturationValue();
			serverValue = area.getSevereValue();
		} else {
			BdapSubArea subarea = subareaMapper.selectById(Long.parseLong(subAreaId));
			if (ToolUtil.isEmpty(subarea)) {
				return;
			}
			warningValue = subarea.getWarningValue();
			saturationValue = subarea.getSaturationValue();
			serverValue = subarea.getSevereValue();
		}
		if (timeType.equals("日")) {
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(upTime);
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaHmModel> subAreaDmList = subAreaHmMapper.selectsubAreaDmPeakPassenge(mytimeType);
				for (int i = 0; i < subAreaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					SubAreaHmModel subAreaHmModel = subAreaDmList.get(i);
					objs[0] = areaName;
					objs[1] = subAreaHmModel.getStatDate();
					objs[2] = subAreaHmModel.getPeakAllPerson();
					objs[3] = subAreaHmModel.getPeakFluidPerson();
					objs[4] = saturationValue;
					objs[5] = warningValue;
					objs[6] = serverValue;
					dataList.add(objs);
				}
			}else{
				List<AreaHmModel> areaDmList = areaHmMapper.selectAreaDmPeakPassenge(mytimeType);
				for (int i = 0; i < areaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					AreaHmModel areaHmModel = areaDmList.get(i);
					objs[0] = areaName;
					objs[1] = areaHmModel.getStatDate();
					objs[2] = areaHmModel.getPeakAllPerson();
					objs[3] = areaHmModel.getPeakFluidPerson();
					objs[4] = saturationValue;
					objs[5] = warningValue;
					objs[6] = serverValue;
					dataList.add(objs);
				}
			}
		}
		if (timeType.equals("月")) {
			// 每月最后一天日期
			mytimeType.setBeginTime(beginTime + "01");
			mytimeType.setUpTime(beginTime + "12");
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaDmModel> subAreaDmList = subAreaDmMapper.selectSubAreaPeakPassengerByMon(mytimeType);
				for (int i = 0; i < subAreaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					SubAreaDmModel subAreaDmModel = subAreaDmList.get(i);
					objs[0] = areaName;
					objs[1] = subAreaDmModel.getStatMonth();
					objs[2] = subAreaDmModel.getPeakAllPerson();
					objs[3] = subAreaDmModel.getPeakFluidPerson();
					objs[4] = saturationValue;
					objs[5] = warningValue;
					objs[6] = serverValue;
					dataList.add(objs);
				}
			}else{
				List<AreaDmModel> areaDmList = areaDmMapper.selectAreaPeakPassengerByMon(mytimeType);
				for (int i = 0; i < areaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					AreaDmModel areaDmModel = areaDmList.get(i);
					objs[0] = areaName;
					objs[1] = areaDmModel.getStatMonth();
					objs[2] = areaDmModel.getPeakAllPerson();
					objs[3] = areaDmModel.getPeakFluidPerson();
					objs[4] = saturationValue;
					objs[5] = warningValue;
					objs[6] = serverValue;
					dataList.add(objs);
				}
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 客源地导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param areaType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param areaname
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/originExport")
	@ResponseBody
	public void originExport(String beginTime,String upTime, String areaType,String areaId, String subAreaId, String areaname, HttpServletRequest request,
			HttpServletResponse response){
		if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(upTime)) {
    		return;
    	}
		String[] rowsName = new String[] { "区域", "时间", "省/市/区县", "客源地(客流人)"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "客源地";
		String areaName = areaname;
		String exportTime = beginTime + "-" + upTime;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
    	List<String> stringList = new ArrayList<String>();//客源地解析集合
    	List<String> areaList = new ArrayList<String>();//区域信息集合
    	Map<String, List<Integer>> splitToMap = new HashMap<>();
    	List<Integer> sumListOrigin = new ArrayList<Integer>();//求和后的list
    	List<SubAreaDmModel> subareaPopPropDmList = new ArrayList<SubAreaDmModel>();
		List<AreaDmModel> areaPopDmList = new ArrayList<AreaDmModel>();
    	if(areaType.equals("省份")){
			mytimeType.setBeginTime(beginTime);
	    	mytimeType.setUpTime(upTime);
	    	if (ToolUtil.isNotEmpty(subAreaId)) {
				subareaPopPropDmList = subAreaDmMapper.selectSubAreaOriginProvince(mytimeType);
				for (SubAreaDmModel subAreaDmModel : subareaPopPropDmList) {
					String provinceUsers = subAreaDmModel.getProvinceUsers();
					stringList.add(provinceUsers);
				}
			}else{
				areaPopDmList = areaDmMapper.selectAreaOriginProvince(mytimeType);
				for (AreaDmModel bdapAreaPopPropDm : areaPopDmList) {
					String provinceUsers = bdapAreaPopPropDm.getProvinceUsers();
					stringList.add(provinceUsers);
				}
			}
    	}
    	if(areaType.equals("城市")){
			mytimeType.setBeginTime(beginTime);
	    	mytimeType.setUpTime(upTime);
	    	if (ToolUtil.isNotEmpty(subAreaId)) {
				List<SubAreaDmModel> subAreaDmCityList = subAreaDmMapper.selectSubAreaOriginCity(mytimeType);
				for (SubAreaDmModel subAreaDmModel : subAreaDmCityList) {
					String originPersonCity = subAreaDmModel.getOriginPersonCity();
					stringList.add(originPersonCity);
				}
			}else{
				List<AreaDmModel> selectAreaOriginCity = areaDmMapper.selectAreaOriginCity(mytimeType);
				for (AreaDmModel areaDmModel : selectAreaOriginCity) {
					String originPersonCity = areaDmModel.getOriginPersonCity();
					stringList.add(originPersonCity);
				}
			}
    	}
    	if (areaType.equals("区县")) {
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(upTime);
			if (ToolUtil.isNotEmpty(subAreaId)) {
				List<SubAreaDmModel> subAreaDmCityList = subAreaDmMapper.selectSubAreaUserCounty(mytimeType);
				for (SubAreaDmModel subAreaDmModel : subAreaDmCityList) {
					String countyUsers = subAreaDmModel.getSnCountyUsers();
					stringList.add(countyUsers);
				}
			}else{
				List<AreaDmModel> selectAreaOriginCity = areaDmMapper.selectAreaUserCounty(mytimeType);
				for (AreaDmModel areaDmModel : selectAreaOriginCity) {
					String countyUsers = areaDmModel.getSnCountyUsers();
					stringList.add(countyUsers);
				}
			}
		}
    	splitToMap = MySplitUtilToList.splitToMap(stringList);
    	List<String> mapKey  = new LinkedList<>();
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
			String key = entry.getKey();
			mapKey.add(key);
		}
		
		Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();  
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
	    	String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sortedMap.put(key, sum);
		}   
	    Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String,Integer>>() {
	        @Override
	        public int compare(Entry<String, Integer> o1,
	                Entry<String, Integer> o2) {
	            return o2.getValue()-o1.getValue();
	        }
	    };
	    
	    // map转换成list进行排序
	    //将排序后的map中的key值取出放入list（sortedMapKey）中
	    List<Map.Entry<String, Integer>> listMap = new ArrayList<Map.Entry<String,Integer>>(sortedMap.entrySet());
	    Collections.sort(listMap,valueComparator);
	    for (Map.Entry<String, Integer> entry : listMap) {
	    	String key = entry.getKey();
	    	Integer value = entry.getValue();
	    	sumListOrigin.add(value);
	    	areaList.add(key);
	    }  
		for(int j=0;j<areaList.size();j++){
			Object[] objs = new Object[rowsName.length];
			objs[0] = areaName;
			objs[1] = exportTime;
			objs[2] = areaList.get(j);
			objs[3] = sumListOrigin.get(j);
			dataList.add(objs);
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	
	/**
	 * 年龄分布导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param timeType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param areaname
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/ageExport")
	@ResponseBody
	public void ageExport(String beginTime,String upTime,String timeType,String areaId,String subAreaId,String areaname,HttpServletRequest request,
			HttpServletResponse response){
		if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(upTime)||ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(timeType)) {
    		return;
    	}
		String[] rowsName = new String[] { "区域", "时间", "年龄分布(0-9)/人", "年龄分布(10-19)/人", "年龄分布(20-29)/人", "年龄分布(30-39)/人", "年龄分布(40-49)/人", "年龄分布(50-59)/人", "年龄分布(60+)/人"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "年龄分布";
		String areaName = areaname;
    	AgeSegmentation age = new AgeSegmentation();
    	Map<String,Integer> ageBeginMonthMap = new LinkedHashMap<String,Integer>();//求和后的map（月份）
    	Map<String,Integer> ageUpMap = new LinkedHashMap<String,Integer>();//求和后的map（月份）
    	Map<String,ArrayList<Integer>> allAgeMap = new LinkedHashMap<String,ArrayList<Integer>>();//对两个时间段的求和数据汇总
    	Set<String> ageTimeList = new LinkedHashSet<String>();//存放时间集合
    	List<String> ageSegmentation = new ArrayList<String>();//存放年龄分段字段
    	List<String> selectAgeList = new ArrayList<String>();//存放解析集合
    	List<String> ageListBeginMonth = new ArrayList<String>();//存放解析集合(月份）
    	List<String> ageListUpMonth = new ArrayList<String>();//存放解析集合（月份）
    	List<Integer> sumListAge = new ArrayList<Integer>();//求和后的list
    	List<Integer> sumListBeginTime = new ArrayList<Integer>();//求和后的list(月份）
    	List<Integer> sumListUptime = new ArrayList<Integer>();//求和后的list(月份）
    	Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
    	Map<String, List<Integer>> splitToMapMonBegin = new LinkedHashMap<>();//月份
    	Map<String, List<Integer>> splitToMapMonUp = new LinkedHashMap<>();
    	Map<String,ArrayList<String>> map = new LinkedHashMap<String,ArrayList<String>>();//存放根据时间查询处理的结果集
    	Map<String,Map<String, List<Integer>>> convertMap  = new LinkedHashMap<String,Map<String, List<Integer>>>();//存放根据时间拆分后的map
    	List<String> timeKey = new ArrayList<String>();//存放时间key
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
    	if(StringUtils.isNotEmpty(timeType)){
    		if(timeType.equals("日")){
    			if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(upTime)) {
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(upTime);
					// 1.根据时间查询出性别数据
					// 2.根据拆分方法splitUtil.splitToMap将数据拆分成Map<String,
					// Integer[]>形式（0-9，[20,30……]、10-19，[60,300……]……)
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaAge = subAreaDmMapper.selectSubAreaAge(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaAge) {
							String ageUsers = subAreaDmModel.getAgeUsers();
							selectAgeList.add(ageUsers);
							String statDate = subAreaDmModel.getStatDate();
							if (map.containsKey(statDate)) {
								ArrayList<String> arrayList = map.get(statDate);
								arrayList.add(ageUsers);
							} else {
								ArrayList<String> arrayList = new ArrayList<String>();
								arrayList.add(ageUsers);
								map.put(statDate, arrayList);
							}
						}
					}else{
						List<AreaDmModel> areaAge = areaDmMapper.selectAreaAge(mytimeType);
						for (AreaDmModel areaDmModel : areaAge) {
							String ageUsers = areaDmModel.getAgeUsers();
							selectAgeList.add(ageUsers);
							String statDate = areaDmModel.getStatDate();
							if (map.containsKey(statDate)) {
								ArrayList<String> arrayList = map.get(statDate);
								arrayList.add(ageUsers);
							} else {
								ArrayList<String> arrayList = new ArrayList<String>();
								arrayList.add(ageUsers);
								map.put(statDate, arrayList);
							}
						}
					}
					// 取map中的key（时间：20171106）值，存入时间集合（timeKey）中，用工具类拆分value值
					// 放入map（convertMap）中，convertMap结构（20171106，0-9，[20,30……]、10-19，[60,300……]……，20171109，0-9，[20,30……]、10-19，[60,300……]……）
					for (Entry<String, ArrayList<String>> entry : map.entrySet()) {
						String key = entry.getKey();
						timeKey.add(key);
						ArrayList<String> arrayList = map.get(key);
						Map<String, List<Integer>> hashMap = MySplitUtilToList.splitToMap(arrayList);
						convertMap.put(key, hashMap);
					}
					Collections.sort(timeKey);
					splitToMap = MySplitUtilToList.splitToMap(selectAgeList);// 柱状图数据
				}
			}

			if (timeType.equals("月")) {
				if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(upTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					DateFormat fmtDateTime = new SimpleDateFormat("yyyyMMdd");
					Date date = null;
					try {
						date = fmtDateTime.parse(beginTime);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					String firstday = null;
					String lastday = null;
					Calendar cale = Calendar.getInstance();
					cale.setTime(date);
					// 获取beginTime的最后一天
					cale.add(Calendar.MONTH, 1);
					cale.set(Calendar.DAY_OF_MONTH, 0);
					lastday = sdf.format(cale.getTime());
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(lastday);
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaAge = subAreaDmMapper.selectSubAreaAge(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaAge) {
							String ageUsers = subAreaDmModel.getAgeUsers();
							ageListBeginMonth.add(ageUsers);
						}
					}else{
						List<AreaDmModel> areaAge = areaDmMapper.selectAreaAge(mytimeType);
						for (AreaDmModel areaDmModel : areaAge) {
							String ageUsers = areaDmModel.getAgeUsers();
							ageListBeginMonth.add(ageUsers);
						}
					}
					try {
						date = fmtDateTime.parse(upTime);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					cale.setTime(date);
					cale.add(Calendar.MONTH, 0);
					cale.set(Calendar.DAY_OF_MONTH, 1);
					firstday = sdf.format(cale.getTime());
					mytimeType.setBeginTime(firstday);
					mytimeType.setUpTime(upTime);
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaAge = subAreaDmMapper.selectSubAreaAge(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaAge) {
							String ageUsers = subAreaDmModel.getAgeUsers();
							ageListUpMonth.add(ageUsers);
						}
					}else{
						List<AreaDmModel> areaAge = areaDmMapper.selectAreaAge(mytimeType);
						for (AreaDmModel areaDmModel : areaAge) {
							String ageUsers = areaDmModel.getAgeUsers();
							ageListUpMonth.add(ageUsers);
						}
					}
					
					// 1.根据时间查询出性别数据
					// 2.根据拆分方法splitUtil.splitToMap将数据拆分成Map<String,
					// Integer[]>形式（0-9，[20,30……]、10-19，[60,300……]……)
					// 3.将查询时间2017-9-20,2017-10-15格式化为2017-9，2017-10形式
					// 4.查询出2017-9月份的20号至9月最后一天的数据
					// 5.查询出2017-10月份的1号到15的数据
					// 6.根据时间2017-9-20,2017-10-15查询出数据（柱状图数据）
					// 5.将结果封装到对应的集合中
					// 根据时间查询（柱状图数据）
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(upTime);
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaAge = subAreaDmMapper.selectSubAreaAge(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaAge) {
							String ageUsers = subAreaDmModel.getAgeUsers();
							selectAgeList.add(ageUsers);
						}
					}else{
						List<AreaDmModel> areaAge = areaDmMapper.selectAreaAge(mytimeType);
						for (AreaDmModel areaDmModel : areaAge) {
							String ageUsers = areaDmModel.getAgeUsers();
							selectAgeList.add(ageUsers);
						}
					}
					splitToMap = MySplitUtilToList.splitToMap(selectAgeList);
					String formatBeginTime = beginTime.substring(0, 6);
					String formatUpTime = upTime.substring(0, 6);
					if (ageListBeginMonth.size() > 0 || ageListUpMonth.size() > 0) {
						ageTimeList.add(formatBeginTime);
						ageTimeList.add(formatUpTime);
					}
					splitToMapMonBegin = MySplitUtilToList.splitToMap(ageListBeginMonth);
					splitToMapMonUp = MySplitUtilToList.splitToMap(ageListUpMonth);
				}
			}
    	}
    	//遍历时间集合（timeKey）
    	Map<String, List<Integer>> splitToMapList = new LinkedHashMap<String, List<Integer>>();
    	List<String> ageSegmentationList = new ArrayList<String>();
    	ageSegmentationList.add("0-9");
    	ageSegmentationList.add("10-19");
    	ageSegmentationList.add("20-29");
    	ageSegmentationList.add("30-39");
    	ageSegmentationList.add("40-49");
    	ageSegmentationList.add("50-59");
    	ageSegmentationList.add("60+");
    	for(int i=0;i<timeKey.size();i++){
    		String string = timeKey.get(i);//string：时间段20171106
    		ageTimeList.add(string);
    		Map<String, List<Integer>> hashMap = convertMap.get(string);//根据时间取value（0-9，[20,30……]、10-19，[60,300……]……）
    		
    			for(int j=0;j<ageSegmentationList.size();j++){
    				String keyStr = ageSegmentationList.get(j);
    				if(hashMap.containsKey(keyStr)){
    					continue;
    				}else{
    					List<Integer> arrayList = new ArrayList<Integer>();
    					arrayList.add(0);
    					hashMap.put(keyStr, arrayList);
    				}
    			}
    		
    		for (Entry<String, List<Integer>> entry : hashMap.entrySet()) {  
    			String key = entry.getKey();//key：年龄分段 0-9……
    			List<Integer> list = hashMap.get(key);//根据key取value
    			Integer sum = 0;
    			for (Integer integer : list) {
    				sum = sum + integer;
				}
    			List<Integer> sumlist = new ArrayList<Integer>();
    			sumlist.add(sum);
    			if(splitToMapList.containsKey(key)){
					 List<Integer> splitList = splitToMapList.get(key);
					 splitList.add(sum);
				}else{
					List<Integer> arrayList = new ArrayList<Integer>();
					arrayList.add(sum);
					splitToMapList.put(key, sumlist);
				}
    		}
    	}
    	
    	//1.根据拆分的map取出其key值放入到集合中
    	//2.对集合进行排序Collections.sort(mapKey);
    	//3.遍历排序后的集合，根据key值取拆分的map中的value值进行求和
    	List<String> mapKey  = new ArrayList<>();
    	for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
			String key = entry.getKey();
			mapKey.add(key);
		}
    	Collections.sort(mapKey);
    	for(int j=0;j<mapKey.size();j++){
    		String key = mapKey.get(j);
    		List<Integer> list = splitToMap.get(key);
    		Integer sum = 0;
    		for (Integer integer : list) {
    			sum = sum + integer;
			}
			ageSegmentation.add(key);
			sumListAge.add(sum);
    	}
    	
    	//对相应的月份的值进行求和
    	for (Entry<String, List<Integer>> entry : splitToMapMonUp.entrySet()) {  
			String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			//ageSegmentation.add(key);
			sumListBeginTime.add(sum);
			ageUpMap.put(key,sum);//ageBeginMonthMap
		}
    	
    	//对相应的月份的值进行求和
    	for (Entry<String, List<Integer>> entry : splitToMapMonBegin.entrySet()) {  
			String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sumListUptime.add(sum);//ageBeginMonthMap
			ageBeginMonthMap.put(key, sum);//ageUpMap
		}
    	
    	//按月查询的数据，折线图数据（2017-9,2017-10）
    	for(int i = 0;i<ageSegmentation.size();i++){
    		String key = ageSegmentation.get(i);
    		Integer ageBegin = ageBeginMonthMap.get(key);//查询开始时间的月份数据
    		Integer ageUp = ageUpMap.get(key);//查询结束时间的月份数据
    		List<Integer> list = new ArrayList<>();
    		if(ageBegin==null){
    			list.add(0);
    		}else{
    			list.add(ageBegin);
    		}
    		if(ageUp==null){
    			list.add(0);
    		}else{
    			list.add(ageUp);
    		}
    		allAgeMap.put(key,(ArrayList<Integer>) list);
    	}
    	List<String> exportTimeList =  new ArrayList<String>();
    	for(String str:ageTimeList){
    		exportTimeList.add(str);
    	}
    	if(timeType.equals("日")){
    		List<Integer> nine = splitToMapList.get("0-9");
    		List<Integer> nineteen = splitToMapList.get("10-19");
    		List<Integer> twentyNine = splitToMapList.get("20-29");
    		List<Integer> thirtyNine = splitToMapList.get("30-39");
    		List<Integer> foutyNine = splitToMapList.get("40-49");
    		List<Integer> fiftyNine = splitToMapList.get("50-59");
    		List<Integer> sisty = splitToMapList.get("60+");
    		for(int i=0;i<exportTimeList.size();i++){
    			Object[] objs = new Object[rowsName.length];
    			objs[0] = areaName;
    			objs[1] = exportTimeList.get(i);
    			objs[2] = nine.get(i);
    			objs[3] = nineteen.get(i);
    			objs[4] = twentyNine.get(i);
    			objs[5] = thirtyNine.get(i);
    			objs[6] = foutyNine.get(i);
    			objs[7] = fiftyNine.get(i);
    			objs[8] = sisty.get(i);
    			dataList.add(objs);
    		}
    	}
    	if(timeType.equals("月")){
    		List<Integer> nine = allAgeMap.get("0-9");
    		List<Integer> nineteen = allAgeMap.get("10-19");
    		List<Integer> twentyNine = allAgeMap.get("20-29");
    		List<Integer> thirtyNine = allAgeMap.get("30-39");
    		List<Integer> foutyNine = allAgeMap.get("40-49");
    		List<Integer> fiftyNine = allAgeMap.get("50-59");
    		List<Integer> sisty = allAgeMap.get("60+");
    		for(int i=0;i<exportTimeList.size();i++){
    			Object[] objs = new Object[rowsName.length];
    			objs[0] = areaName;
				objs[1] = exportTimeList.get(i);
				objs[2] = nine.get(i);
				objs[3] = nineteen.get(i);
				objs[4] = twentyNine.get(i);
				objs[5] = thirtyNine.get(i);
				objs[6] = foutyNine.get(i);
				objs[7] = fiftyNine.get(i);
				objs[8] = sisty.get(i);
				dataList.add(objs);
    		}
    	}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	 /**
	  * 累计客流导出
	  * @Description: TODO
	  * @param @param beginTime
	  * @param @param upTime
	  * @param @param timeType
	  * @param @param areaId
	  * @param @param subAreaId
	  * @param @param areaname
	  * @param @param request
	  * @param @param response
	  * @param @return   
	  * @return Object  
	  * @throws
	  * @author zhangyaoyao
	  * @date 2018年3月5日
	  */
	 @RequestMapping(value = "/cumulativePassengerExport")
	 @ResponseBody
	 public void cumulativePassenger(String beginTime,String upTime,String timeType,String areaId,String subAreaId,String areaname,HttpServletRequest request,
				HttpServletResponse response) {
		if (ToolUtil.isEmpty(beginTime) || ToolUtil.isEmpty(timeType)) {
			return;
		}
		String[] rowsName = new String[] { "区域", "时间", "累计客流(所有人口)", "累计客流(流动人口)" };
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "累计客流";
		String areaName = areaname;
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		if (timeType.equals("日")) {
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(upTime);
			if (ToolUtil.isNotEmpty(subAreaId)) {
				List<SubAreaDmModel> subAreaDmList = subAreaDmMapper.selectSubAreaCumulativePassenger(mytimeType);
				for (int i = 0; i < subAreaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					SubAreaDmModel subAreaDmModel = subAreaDmList.get(i);
					objs[0] = areaName;
					objs[1] = subAreaDmModel.getStatDate();
					objs[2] = subAreaDmModel.getComulativeAllPerson();
					objs[3] = subAreaDmModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			} else {
				List<AreaDmModel> areaDmList = areaDmMapper.selectAreaCumulativePassenger(mytimeType);
				for (int i = 0; i < areaDmList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					AreaDmModel areaDmModel = areaDmList.get(i);
					objs[0] = areaName;
					objs[1] = areaDmModel.getStatDate();
					objs[2] = areaDmModel.getComulativeAllPerson();
					objs[3] = areaDmModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			}
		}
		if (timeType.equals("月")) {
			List<String> timeList = TimeUtil.getLastDayOfMonth(beginTime);
			mytimeType.setBeginTime(StringUtil.concat(timeList));
			if (ToolUtil.isNotEmpty(subAreaId)) {
				List<SubAreaDtModel> subAreaDtList = subAreaDtMapper.selectSubAreaCumulative(mytimeType);
				for (int i = 0; i < subAreaDtList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					SubAreaDtModel subAreaDtModel = subAreaDtList.get(i);
					objs[0] = areaName;
					objs[1] = subAreaDtModel.getStatDate();
					objs[2] = subAreaDtModel.getComulativeAllPerson();
					objs[3] = subAreaDtModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			} else {
				List<AreaDtModel> areaDtList = areaDtMapper.selectAreaCumulative(mytimeType);
				for (int i = 0; i < areaDtList.size(); i++) {
					Object[] objs = new Object[rowsName.length];
					AreaDtModel areaDtModel = areaDtList.get(i);
					objs[0] = areaName;
					objs[1] = areaDtModel.getStatDate();
					objs[2] = areaDtModel.getComulativeAllPerson();
					objs[3] = areaDtModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	  }
	 
	 /**
	  * 逗留情况导出
	  * @Description: TODO
	  * @param @param beginTime
	  * @param @param areaId
	  * @param @param subAreaId
	  * @param @param timeType
	  * @param @return   
	  * @return Object  
	  * @throws
	  * @author zhangyaoyao
	  * @date 2018年3月5日
	  */
	 @RequestMapping(value = "/staySituationExport")
	 @ResponseBody
	 public void stayPoupation(String beginTime,String timeType,String areaId,String subAreaId,String areaname,HttpServletRequest request,
				HttpServletResponse response) {
	    	if(ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(timeType)) {
	    		return;
	    	}
	    	String[] rowsName = new String[] { "区域", "时间", "逗留时长", "客流(人)"};
			List<Object[]> dataList = new ArrayList<Object[]>();
			String fileName = "逗留情况";
			String areaName = areaname;
			String exportTime = beginTime;
	    	MyTimeType mytimeType = new MyTimeType();
	    	mytimeType.setAreaId(areaId);
	    	mytimeType.setSubAreaId(subAreaId);
	    	List<String> stringList = new ArrayList<String>();//逗留情况解析集合
	    	List<String> staySituationList = new ArrayList<String>();//逗留情况分布用户数集合
	    	Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
	    	List<Integer> sumListStaySituation = new ArrayList<Integer>();//求和后的list
	    	if(timeType.equals("天")){
	    		mytimeType.setBeginTime(beginTime);
				if (ToolUtil.isNotEmpty(subAreaId)) {
					List<BdapSubareaStayMm> subAreaStayMM = subAreaStayMmMapper.selectSubAreaStayMM(mytimeType);
					for (BdapSubareaStayMm bdapSubareaStayMm : subAreaStayMM) {
						String stayTimeUsers = bdapSubareaStayMm.getStayTimeUsers();
						stringList.add(stayTimeUsers);
					}
				}else{
					List<BdapAreaStayMm> areaStayMM = areaStayMmMapper.selectAreaStayMM(mytimeType);
					for (BdapAreaStayMm bdapAreaStayMm : areaStayMM) {
						String stayTimeUsers = bdapAreaStayMm.getStayTimeUsers();
						stringList.add(stayTimeUsers);
					}
				}
				splitToMap = MySplitUtilToList.splitToMap(stringList);
	    	}
	    	if(timeType.equals("小时")){
	    		mytimeType.setBeginTime(beginTime);
				if (ToolUtil.isNotEmpty(subAreaId)) {
					List<BdapSubareaPopPropDm> selectStaySituationDm = subAreaDmMapper.selectStaySituationDm(mytimeType);
					for (BdapSubareaPopPropDm bdapSubareaPopPropDm : selectStaySituationDm) {
						String stayTimeUsers = bdapSubareaPopPropDm.getStayTimeUsers();
						stringList.add(stayTimeUsers);
					}
				}else{
					List<BdapAreaPopPropDm> selectAreaStaySituationDm = areaDmMapper.selectAreaStaySituationDm(mytimeType);
					for (BdapAreaPopPropDm bdapAreaPopPropDm : selectAreaStaySituationDm) {
						String stayTimeUsers = bdapAreaPopPropDm.getStayTimeUsers();
						stringList.add(stayTimeUsers);
					}
				}
				splitToMap = MySplitUtilToList.splitToMap(stringList);
	    	}
	    	List<String> mapKey  = new LinkedList<>();
			for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
				String key = entry.getKey();
				mapKey.add(key);
			}
	    	//构造消费水平分布map，根据value进行排序
	    	Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();  
			for(int i=0;i<mapKey.size();i++){
				String string = mapKey.get(i);
				int indexOf = string.indexOf("-");
				String substringStr = string.substring(indexOf+1,string.length());
				if(string.contains("+")){
					substringStr = "300";
				}
				sortedMap.put(string, Integer.parseInt(substringStr));
			}
			Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String,Integer>>() {
			        @Override
			        public int compare(Entry<String, Integer> o1,
			                Entry<String, Integer> o2) {
			            return o1.getValue()-o2.getValue();
			        }
			    };
			    // map转换成list进行排序
			    //将排序后的map中的key值取出放入list（sortedMapKey）中
			    List<Map.Entry<String, Integer>> listMap = new ArrayList<Map.Entry<String,Integer>>(sortedMap.entrySet());
			    Collections.sort(listMap,valueComparator);
			    List<String> sortedMapKey  = new LinkedList<>();
			    for (Map.Entry<String, Integer> entry : listMap) {
		        String key = entry.getKey();
		        sortedMapKey.add(key);
		    }
			//根据list（sortedMapKey）中的值，去splitToMap中取对应key值的value进行求和计算
	    	for(int j=0;j<sortedMapKey.size();j++){
	    		String key = sortedMapKey.get(j);
	    		List<Integer> value = splitToMap.get(key);
	    		Integer sum = 0;
				for (Integer integer : value) {
					sum = sum + integer;
				}
				sumListStaySituation.add(sum);
				staySituationList.add(key);
	    	}
		    for(int k=0;k<staySituationList.size();k++){
		    	Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = exportTime;
				objs[2] = staySituationList.get(k);
				objs[3] = sumListStaySituation.get(k);
				dataList.add(objs);
			}
			ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
		}
	 
	 /**
	  * 客流密度导出
	  * @Description: TODO
	  * @param @param beginTime
	  * @param @param timeType
	  * @param @param areaId
	  * @param @param subAreaId
	  * @param @param areaname
	  * @param @param request
	  * @param @param response
	  * @param @return   
	  * @return Object  
	  * @throws
	  * @author zhangyaoyao
	  * @date 2018年3月5日
	  */
	@RequestMapping(value = "/passengerDensityExport")
	@ResponseBody
	public void passengerDensityExport(String beginTime, @RequestParam(required = false) String upTime, String timeType,String areaId, String subAreaId, String areaname, HttpServletRequest request,
		HttpServletResponse response) {
		String[] rowsName = new String[] { "区域", "时间", "客流(人)", "密度指数" };
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "客流密度";
		String areaName = areaname;
		String name = null;
		if (ToolUtil.isEmpty(areaId) || ToolUtil.isEmpty(beginTime) || ToolUtil.isEmpty(timeType)) {
			return;
		}
		int saturationValue = 0;
		if (ToolUtil.isEmpty(subAreaId)) {
			BdapArea area = areaMapper.selectById(Long.parseLong(areaId));
			if (ToolUtil.isEmpty(area)) {
				return;
			}
			saturationValue = area.getSaturationValue();
			name = area.getName();
		} else {
			BdapSubArea subarea = subareaMapper.selectById(Long.parseLong(subAreaId));
			if (ToolUtil.isEmpty(subarea)) {
				return;
			}
			saturationValue = subarea.getSaturationValue();
			name = subarea.getName();
		}
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		if (timeType.equals("月")) {
			mytimeType.setUpTime(upTime);
		}
		if (timeType.equals("天")) {
			mytimeType.setUpTime(beginTime);
		}
		mytimeType.setBeginTime(beginTime);
		if(ToolUtil.isNotEmpty(subAreaId)){
			List<SubAreaDmModel> subAreaCumulativePassenger = subAreaDmMapper.selectSubAreaCumulativePassenger(mytimeType);
			for (int k = 0; k < subAreaCumulativePassenger.size(); k++) {
				Object[] objs = new Object[rowsName.length];
				SubAreaDmModel subAreaDmModel = subAreaCumulativePassenger.get(k);
				String comulativeAllPerson = subAreaDmModel.getComulativeAllPerson();
				objs[0] = areaName;
				objs[1] = subAreaDmModel.getStatDate();
				objs[2] = subAreaDmModel.getComulativeAllPerson();
				objs[3] = AreaUtil.getPassengerDensity(saturationValue, Integer.parseInt(comulativeAllPerson));
				dataList.add(objs);
			}
		}else{
			List<AreaDmModel> areaCumulativePassenger = areaDmMapper.selectAreaCumulativePassenger(mytimeType);
			for (int k = 0; k < areaCumulativePassenger.size(); k++) {
				Object[] objs = new Object[rowsName.length];
				AreaDmModel areaDmModel = areaCumulativePassenger.get(k);
				String comulativeAllPerson = areaDmModel.getComulativeAllPerson();
				objs[0] = areaName;
				objs[1] = areaDmModel.getStatDate();
				objs[2] = areaDmModel.getComulativeAllPerson();
				objs[3] = AreaUtil.getPassengerDensity(saturationValue, Integer.parseInt(comulativeAllPerson));
				dataList.add(objs);
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 常驻人口导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param areaname
	 * @param @param request
	 * @param @param response   
	 * @return void  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/permanentPopulationExport")
	@ResponseBody
	public void permanentPopulationExport(String beginTime, String areaId, String subAreaId, String areaname, HttpServletRequest request,
			HttpServletResponse response) {
		if (ToolUtil.isEmpty(areaId) || ToolUtil.isEmpty(beginTime)) {
			return;
		}
		String[] rowsName = new String[] { "区域", "时间(月份)", "人口"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "常驻人口";
		String areaName = areaname;
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		// 每月最后一天日期
		List<String> timeList = TimeUtil.getLastDayOfMonth(beginTime);
		mytimeType.setBeginTime(StringUtil.concat(timeList));
		if(ToolUtil.isNotEmpty(subAreaId)){
			List<SubAreaDtModel> subAreaPermanentPeople = subAreaDtMapper.seletcSubAreaPermanentPeople(mytimeType);
			for (SubAreaDtModel subAreaDtModel : subAreaPermanentPeople) {
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = subAreaDtModel.getStatDate();
				objs[2] = subAreaDtModel.getStayLocalUsers();
				dataList.add(objs);
			}
		}else{
			List<AreaDtModel> areaPermanentPeople = areaDtMapper.seletcAreaPermanentPeople(mytimeType);
			for (AreaDtModel areaDtModel : areaPermanentPeople) {
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = areaDtModel.getStatDate();
				objs[2] = areaDtModel.getStayLocalUsers();
				dataList.add(objs);
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 工作人口导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/workForceExport")
    @ResponseBody
    public void workForce(String beginTime,String areaId,String subAreaId, String areaname, HttpServletRequest request,
			HttpServletResponse response) {
    	if(ToolUtil.isEmpty(beginTime)) {
    		return;
    	}
    	String[] rowsName = new String[] { "区域", "时间(月份)", "人口"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "工作人口";
		String areaName = areaname;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
		//每月最后一天日期
		List<String> timeList = TimeUtil.getLastDayOfMonth(beginTime);
		mytimeType.setBeginTime(StringUtil.concat(timeList));
		//查找最近一年的所有月份数据
		if(ToolUtil.isNotEmpty(subAreaId)){
			List<SubAreaDtModel> seletcSubAreaWorkingPopulation = subAreaDtMapper.seletcSubAreaWorkingPopulation(mytimeType);
			for (SubAreaDtModel subAreaDt : seletcSubAreaWorkingPopulation) {
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = subAreaDt.getStatDate();
				objs[2] = subAreaDt.getWorkLocalUsers();
				dataList.add(objs);
			}
		}else{
			List<AreaDtModel> areaWorkingPopulation = areaDtMapper.seletcAreaWorkingPopulation(mytimeType);
			for (AreaDtModel areaDtModel : areaWorkingPopulation) {
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = areaDtModel.getStatDate();
				objs[2] = areaDtModel.getWorkLocalUsers();
				dataList.add(objs);
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }
	
	/**
	 * 途经人口导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param timeType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/passingPopulationExport")
	@ResponseBody
	public void passingPopulation(String beginTime, String upTime, String timeType, String areaId, String subAreaId, String areaname, HttpServletRequest request,
		HttpServletResponse response) {
		if (ToolUtil.isEmpty(beginTime) || ToolUtil.isEmpty(timeType)) {
			return;
		}
		String[] rowsName = new String[] { "区域", "时间(天/小时)", "客流(人)"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "途经人口";
		String areaName = areaname;
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		if (timeType.equals("天")) {
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(upTime);
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaDmModel> subAreaCumulativePassenger = subAreaDmMapper.selectSubAreaCumulativePassenger(mytimeType);
				for (SubAreaDmModel subAreaDmModel : subAreaCumulativePassenger) {
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = subAreaDmModel.getStatDate();
					objs[2] = subAreaDmModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			}else{
				List<AreaDmModel> areaCumulativePassenger = areaDmMapper.selectAreaCumulativePassenger(mytimeType);
				for (AreaDmModel areaDmModel : areaCumulativePassenger) {
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = areaDmModel.getStatDate();
					objs[2] = areaDmModel.getComulativeFluidPerson();
					dataList.add(objs);
				}
			}
		}
		if (timeType.equals("小时")) {
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(beginTime);
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaHmModel> selectSubAreaPopulation = subAreaHmMapper.selectSubAreaPopulation(mytimeType);
				for (SubAreaHmModel subAreaHmModel : selectSubAreaPopulation) {
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = subAreaHmModel.getStatHour();
					objs[2] = subAreaHmModel.getPassingPerson();
					dataList.add(objs);
				}
			}else{
				List<AreaHmModel> selectAreaPassingPerson = areaHmMapper.selectAreaPassingPerson(mytimeType);
				for (AreaHmModel areaHmModel : selectAreaPassingPerson) {
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = areaHmModel.getStatHour();
					objs[2] = areaHmModel.getPassingPerson();
					dataList.add(objs);
				}
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 出行人口导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param timeType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param areaname
	 * @param @param request
	 * @param @param response
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/travelPopulationExport")
    @ResponseBody
    public void travelPopulation(String beginTime, String upTime, String timeType, String areaId, String subAreaId, String areaname, HttpServletRequest request,
    	HttpServletResponse response) {
    	if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(timeType)) {
    		return;
    	}
    	String[] rowsName = new String[] { "区域", "时间(天/小时)", "客流(人)"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "出行人口";
		String areaName = areaname;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
		mytimeType.setBeginTime(TimeUtil.getMonth(beginTime.substring(0,6), 2));
		TraceMonth traceMonth = traceMonthMapper.selectPermanentPeople(mytimeType);
		if(ToolUtil.isEmpty(traceMonth)) {
			return;
		}
		BigDecimal permanent = traceMonth.getPermanentPeople();
		if(ToolUtil.isEmpty(permanent)||permanent.intValue()==0) {
			return;
		}
		if(timeType.equals("天")){
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(upTime);
			int population = 0;
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaDmModel> subAreaPermanentPeopleDm = subAreaDmMapper.selectSubAreaPermanentPeopleDm(mytimeType);
				for (SubAreaDmModel subAreaDmModel : subAreaPermanentPeopleDm) {
					String permanentPeople = subAreaDmModel.getPermanentPeople();
					if(ToolUtil.isEmpty(permanentPeople)){
						permanentPeople="0";
					}
					Integer valueOf = Integer.valueOf(permanentPeople);
					if (permanent.intValue() - valueOf < 0) {
						population = 0;
					} else {
						population = permanent.intValue()-valueOf;
					}
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = subAreaDmModel.getStatDate();
					objs[2] = population;
					dataList.add(objs);
				}
			}else{
				List<AreaDmModel> areaPermanentPeopleDm = areaDmMapper.selectAreaPermanentPeopleDm(mytimeType);
				for (AreaDmModel areaDmModel : areaPermanentPeopleDm) {
					String permanentPeople = areaDmModel.getPermanentPeople();
					if(ToolUtil.isEmpty(permanentPeople)){
						permanentPeople="0";
					}
					Integer valueOf = Integer.valueOf(permanentPeople);
					if (permanent.intValue() - valueOf < 0) {
						population = 0;
					} else {
						population = permanent.intValue()-valueOf;
					}
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = areaDmModel.getStatDate();
					objs[2] = population;
					dataList.add(objs);
				}
			}
		}
		if(timeType.equals("小时")){
			mytimeType.setBeginTime(beginTime);
			mytimeType.setUpTime(beginTime);
			int population = 0;
			if(ToolUtil.isNotEmpty(subAreaId)){
				List<SubAreaHmModel> subAreaPopulation = subAreaHmMapper.selectSubAreaPopulation(mytimeType);
				for (SubAreaHmModel subAreaHmModel : subAreaPopulation) {
					String permanentPeople = subAreaHmModel.getPermanentPeople();
					if(ToolUtil.isEmpty(permanentPeople)){
						permanentPeople="0";
					}
					Integer valueOf = Integer.valueOf(permanentPeople);
					if (permanent.intValue() - valueOf < 0) {
						population = 0;
					} else {
						population = permanent.intValue()-valueOf;
					}
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = subAreaHmModel.getStatHour();
					objs[2] = population;
					dataList.add(objs);
				}
			}else{
				List<AreaHmModel> areaPassingPerson = areaHmMapper.selectAreaPassingPerson(mytimeType);
				for (AreaHmModel areaHmModel : areaPassingPerson) {
					String permanentPeople = areaHmModel.getPermanentPeople();
					if(ToolUtil.isEmpty(permanentPeople)){
						permanentPeople="0";
					}
					Integer valueOf = Integer.valueOf(permanentPeople);
					if (permanent.intValue() - valueOf < 0) {
						population = 0;
					} else {
						population = permanent.intValue()-valueOf;
					}
					Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = areaHmModel.getStatHour();
					objs[2] = population;
					dataList.add(objs);
				}
			}
    	}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }
	
	/**
	 * 忠诚度导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月5日
	 */
	@RequestMapping(value = "/loyaltyPopulationExport")
    @ResponseBody
    public void loyaltyPoupation(String beginTime,String areaId,String subAreaId,String areaname,HttpServletRequest request,HttpServletResponse response) {
    	if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(beginTime)) {
    		return;
    	}
    	String[] rowsName = new String[] { "区域","时间", "次数", "客流(人)"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "忠诚度";
		String areaName = areaname;
		String exportTime = beginTime;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
    	List<String> stringList = new ArrayList<String>();//忠诚度解析集合
    	List<String> staySituationList = new ArrayList<String>();//忠诚度分布用户数集合
    	Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
    	List<Integer> sumListStaySituation = new ArrayList<Integer>();//求和后的list
    	mytimeType.setBeginTime(beginTime);
		if (StringUtils.isNotEmpty(subAreaId)) {
			List<BdapSubareaLoyaltyMm> subArealoyalty = subAreaLoyaltyMapper.selectSubArealoyaltyPoupation(mytimeType);
			for (BdapSubareaLoyaltyMm bdapSubareaLoyaltyMm : subArealoyalty) {
				String visitUsers = bdapSubareaLoyaltyMm.getVisitUsers();
				stringList.add(visitUsers);
			}
		}else{
			List<BdapAreaLoyaltyMm> arealoyalty = areaLoyaltyMapper.selectArealoyaltyPoupation(mytimeType);
			for (BdapAreaLoyaltyMm bdapAreaLoyaltyMm : arealoyalty) {
				String visitUsers = bdapAreaLoyaltyMm.getVisitUsers();
				stringList.add(visitUsers);
			}
		}
		splitToMap = MySplitUtilToList.splitToMap(stringList);
    	List<String> mapKey  = new LinkedList<>();
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
			String key = entry.getKey();
			mapKey.add(key);
		}
		Collections.sort(mapKey);
		//根据list（sortedMapKey）中的值，去splitToMap中取对应key值的value进行求和计算
    	for(int j=0;j<mapKey.size();j++){
    		String key = mapKey.get(j);
    		List<Integer> value = splitToMap.get(key);
    		Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sumListStaySituation.add(sum);
			staySituationList.add(key);
    	}
    	for (int i=0;i<staySituationList.size();i++) {
			Object[] objs = new Object[rowsName.length];
			objs[0] = areaName;
			objs[1] = exportTime;
			objs[2] = staySituationList.get(i);
			objs[3] = sumListStaySituation.get(i);
			dataList.add(objs);
		}
    	ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	} 
	
	/**
	 * 性别分布导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param timeType
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月6日
	 */
	@RequestMapping(value = "/sexDistributionExport")
	@ResponseBody
	public void sex(String beginTime, String upTime, String timeType, String areaId, String subAreaId,String areaname,HttpServletRequest request,HttpServletResponse response) {
		if (ToolUtil.isEmpty(areaId) || ToolUtil.isEmpty(upTime) || ToolUtil.isEmpty(beginTime)|| ToolUtil.isEmpty(timeType)) {
			return;
		}
		String[] rowsName = new String[] { "区域","时间", "性別分布(男)/人", "性別分布(女)/人"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "性别分布";
		String areaName = areaname;
		Sex sex = new Sex();
		Map<String, Integer> sexBeginMonthMap = new LinkedHashMap<String, Integer>();// 求和后的map（月份）
		Map<String, Integer> sexUpMap = new LinkedHashMap<String, Integer>();// 求和后的map（月份）
		Map<String, ArrayList<Integer>> allSexMap = new LinkedHashMap<String, ArrayList<Integer>>();// 对两个时间段的求和数据汇总
		Set<String> sexTimeList = new LinkedHashSet<String>();// 存放时间集合
		List<String> sexSegmentation = new ArrayList<String>();// 存放性别字段
		List<String> selectSexList = new ArrayList<String>();// 存放解析集合
		List<String> sexListBeginMonth = new ArrayList<String>();// 存放解析集合(月份）
		List<String> sexListUpMonth = new ArrayList<String>();// 存放解析集合（月份）
		List<Integer> sumListSex = new ArrayList<Integer>();// 求和后的list
		List<Integer> sumListBeginTime = new ArrayList<Integer>();// 求和后的list(月份）
		List<Integer> sumListUptime = new ArrayList<Integer>();// 求和后的list(月份）
		Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
		Map<String, List<Integer>> splitToMapMonBegin = new LinkedHashMap<>();// 月份
		Map<String, List<Integer>> splitToMapMonUp = new LinkedHashMap<>();
		Map<String, ArrayList<String>> map = new LinkedHashMap<String, ArrayList<String>>();// 存放根据时间查询处理的结果集
		Map<String, Map<String, List<Integer>>> convertMap = new LinkedHashMap<String, Map<String, List<Integer>>>();// 存放根据时间拆分后的map
		List<String> timeKey = new ArrayList<String>();// 存放时间key
		MyTimeType mytimeType = new MyTimeType();
		mytimeType.setAreaId(areaId);
		mytimeType.setSubAreaId(subAreaId);
		if (StringUtils.isNotEmpty(timeType)) {
			if (timeType.equals("日")) {
				if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(upTime)) {
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(upTime);
					// 1.根据时间查询出性别数据
					// 2.根据拆分方法splitUtil.splitToMap将数据拆分成Map<String,
					// Integer[]>形式（0-9，[20,30……]、10-19，[60,300……]……)
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaSex = subAreaDmMapper.selectSubAreaSexByTime(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaSex) {
							String sexUsers = subAreaDmModel.getSexUsers();
							selectSexList.add(sexUsers);
							String time = subAreaDmModel.getStatDate();
							if (map.containsKey(time)) {
								ArrayList<String> arrayList = map.get(time);
								arrayList.add(sexUsers);
							} else {
								ArrayList<String> arrayList = new ArrayList<String>();
								arrayList.add(sexUsers);
								map.put(time, arrayList);
							}
						}
					}else{
						List<AreaDmModel> areaSex = areaDmMapper.selectAreaSexByTime(mytimeType);
						for (AreaDmModel areaDmModel : areaSex) {
							String sexUsers = areaDmModel.getSexUsers();
							selectSexList.add(sexUsers);
							String time = areaDmModel.getStatDate();
							if (map.containsKey(time)) {
								ArrayList<String> arrayList = map.get(time);
								arrayList.add(sexUsers);
							} else {
								ArrayList<String> arrayList = new ArrayList<String>();
								arrayList.add(sexUsers);
								map.put(time, arrayList);
							}
						}
					}
					for (Entry<String, ArrayList<String>> entry : map.entrySet()) {
						String key = entry.getKey();
						timeKey.add(key);
						ArrayList<String> arrayList = map.get(key);
						Map<String, List<Integer>> hashMap = MySplitUtilToList.splitToMap(arrayList);
						convertMap.put(key, hashMap);
					}
					Collections.sort(timeKey);
					splitToMap = MySplitUtilToList.splitToMap(selectSexList);
				}
			}

			if (timeType.equals("月")) {
				if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(upTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					DateFormat fmtDateTime = new SimpleDateFormat("yyyyMMdd");
					Date date = null;
					try {
						date = fmtDateTime.parse(beginTime);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					String firstday = null;
					String lastday = null;
					Calendar cale = Calendar.getInstance();
					cale.setTime(date);
					// 获取beginTime的最后一天
					cale.add(Calendar.MONTH, 1);
					cale.set(Calendar.DAY_OF_MONTH, 0);
					lastday = sdf.format(cale.getTime());
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(lastday);
					List<SubAreaDmModel> subAreaSex = new ArrayList<SubAreaDmModel>();
					List<AreaDmModel> areaSex = new ArrayList<AreaDmModel>();
					if(ToolUtil.isNotEmpty(subAreaId)){
						subAreaSex = subAreaDmMapper.selectSubAreaSexByTime(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaSex) {
							String sexUsers = subAreaDmModel.getSexUsers();
							sexListBeginMonth.add(sexUsers);
						}
					}else{
						areaSex = areaDmMapper.selectAreaSexByTime(mytimeType);
						for (AreaDmModel areaDmModel : areaSex) {
							String sexUsers = areaDmModel.getSexUsers();
							sexListBeginMonth.add(sexUsers);
						}
					}
					try {
						date = fmtDateTime.parse(upTime);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					cale.setTime(date);
					cale.add(Calendar.MONTH, 0);
					cale.set(Calendar.DAY_OF_MONTH, 1);
					firstday = sdf.format(cale.getTime());
					mytimeType.setBeginTime(firstday);
					mytimeType.setUpTime(upTime);
					List<SubAreaDmModel> subAreaSexUpTime = new ArrayList<SubAreaDmModel>();
					List<AreaDmModel> areaSexUpTime = new ArrayList<AreaDmModel>();
					if(ToolUtil.isNotEmpty(subAreaId)){
						subAreaSexUpTime = subAreaDmMapper.selectSubAreaSexByTime(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaSexUpTime) {
							String sexUsers = subAreaDmModel.getSexUsers();
							sexListUpMonth.add(sexUsers);
						}
					}else{
						areaSexUpTime = areaDmMapper.selectAreaSexByTime(mytimeType);
						for (AreaDmModel areaDmModel : areaSexUpTime) {
							String sexUsers = areaDmModel.getSexUsers();
							sexListUpMonth.add(sexUsers);
						}
					}
					mytimeType.setBeginTime(beginTime);
					mytimeType.setUpTime(upTime);
					// 1.根据时间查询出性别数据
					// 2.根据拆分方法splitUtil.splitToMap将数据拆分成Map<String,
					// Integer[]>形式（男，[20,30……]、女，[60,300……]……)
					// 3.将查询时间2017-9-20,2017-10-15格式化为2017-9，2017-10形式
					// 4.查询出2017-9月份的20号至9月最后一天的数据
					// 5.查询出2017-10月份的1号到15的数据
					// 6.根据时间2017-9-20,2017-10-15查询出数据（柱状图数据）
					// 5.将结果封装到对应的集合中

					// 根据时间查询（柱状图数据）
					if(ToolUtil.isNotEmpty(subAreaId)){
						List<SubAreaDmModel> subAreaSexDm = subAreaDmMapper.selectSubAreaSexByTime(mytimeType);
						for (SubAreaDmModel subAreaDmModel : subAreaSexDm) {
							String sexUsers = subAreaDmModel.getSexUsers();
							selectSexList.add(sexUsers);
						}
					}else{
						List<AreaDmModel> areaSexDm = areaDmMapper.selectAreaSexByTime(mytimeType);
						for (AreaDmModel areaDmModel : areaSexDm) {
							String sexUsers = areaDmModel.getSexUsers();
							selectSexList.add(sexUsers);
						}
					}
					splitToMap = MySplitUtilToList.splitToMap(selectSexList);
					String formatBeginTime = beginTime.substring(0, 6);
					String formatUpTime = upTime.substring(0, 6);
					if (subAreaSexUpTime.size() > 0 || areaSexUpTime.size() > 0 || subAreaSex.size() > 0 || areaSex.size() > 0) {
						sexTimeList.add(formatBeginTime);
						sexTimeList.add(formatUpTime);
					}
					splitToMapMonBegin = MySplitUtilToList.splitToMap(sexListBeginMonth);
					splitToMapMonUp = MySplitUtilToList.splitToMap(sexListUpMonth);
				}
			}
		}

		Map<String, List<Integer>> splitToMapList = new LinkedHashMap<String, List<Integer>>();
		for (int i = 0; i < timeKey.size(); i++) {
			String string = timeKey.get(i);// string：时间段20171106
			sexTimeList.add(string);
			Map<String, List<Integer>> hashMap = convertMap.get(string);
			for (Entry<String, List<Integer>> entry : hashMap.entrySet()) {
				String key = entry.getKey();// key：性别：男、女
				List<Integer> value = hashMap.get(key);
				Integer sum = 0;
				for (Integer integer : value) {
					sum = sum + integer;
				}
				List<Integer> list = new ArrayList<Integer>();
				list.add(sum);
				if (splitToMapList.containsKey(key)) {
					List<Integer> splitList = splitToMapList.get(key);
					splitList.add(sum);
				} else {
					List<Integer> arrayList = new ArrayList<Integer>();
					arrayList.add(sum);
					splitToMapList.put(key, list);
				}
			}
		}

		// 1.将拆分的数据Map<String,
		// Integer[]>形式（男，[20,30……]、女，[60,300……]……)的value值取出进行求和
		// 2.将key值和求和的值封装
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {
			String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sexSegmentation.add(key);
			sumListSex.add(sum);
		}

		// 对相应的月份的值进行求和
		for (Entry<String, List<Integer>> entry : splitToMapMonUp.entrySet()) {
			String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sumListBeginTime.add(sum);
			sexUpMap.put(key, sum);
		}

		// 对相应的月份的值进行求和
		for (Entry<String, List<Integer>> entry : splitToMapMonBegin.entrySet()) {
			String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sumListUptime.add(sum);
			sexBeginMonthMap.put(key, sum);
		}

		// 根据Key值对相应的月份数据进行封装（按月查询）
		for (int i = 0; i < sexSegmentation.size(); i++) {
			String key = sexSegmentation.get(i);
			Integer sexBegin = sexBeginMonthMap.get(key);
			Integer sexUp = sexUpMap.get(key);
			List<Integer> list = new ArrayList<>();
			if (sexBegin == null) {
				list.add(0);
			} else {
				list.add(sexBegin);
			}
			if (sexUp == null) {
				list.add(0);
			} else {
				list.add(sexUp);
			}
			allSexMap.put(key, (ArrayList<Integer>) list);
		}
		List<String> exportTimeList = new ArrayList<String>();
		for(String exportTime:sexTimeList){
			exportTimeList.add(exportTime);
		}
		if(timeType.equals("日")){
			List<Integer> womenList = splitToMapList.get("女");
			List<Integer> manList = splitToMapList.get("男");
			for(int i=0;i<exportTimeList.size();i++){
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = exportTimeList.get(i);
				objs[2] = manList.get(i);
				objs[3] = womenList.get(i);
				dataList.add(objs);
			}
		}
		if(timeType.equals("月")){
			List<Integer> womenList = allSexMap.get("女");
			List<Integer> manList = allSexMap.get("男");
			for(int i=0;i<exportTimeList.size();i++){
				Object[] objs = new Object[rowsName.length];
				objs[0] = areaName;
				objs[1] = exportTimeList.get(i);
				objs[2] = manList.get(i);
				objs[3] = womenList.get(i);
				dataList.add(objs);
			}
		}
		ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 终端分布导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月6日
	 */
	@RequestMapping(value = "/terminalDistributionExport")
    @ResponseBody
    public void terminalPoupation(String beginTime,String upTime,String areaId,String subAreaId,String areaname,HttpServletRequest request,HttpServletResponse response) {
    	if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(upTime)) {
    		return;
    	}
    	String[] rowsName = new String[] { "区域", "时间", "品牌", "终端数量"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "终端分布";
		String areaName = areaname;
		String exportTime = beginTime + "-" + upTime;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
    	List<String> stringList = new ArrayList<String>();//终端品牌解析集合
    	List<String> terminalList = new ArrayList<String>();//终端品牌信息集合
    	Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
    	List<Integer> sumListTerminal = new ArrayList<Integer>();//求和后的list
    	List<TraceDay> traceDayList = new ArrayList<>();
		mytimeType.setBeginTime(beginTime);
    	mytimeType.setUpTime(upTime);
    	if(ToolUtil.isNotEmpty(subAreaId)){
			List<SubAreaDmModel> subAreaTerminal = subAreaDmMapper.selectSubAreaTerminal(mytimeType);
			for (SubAreaDmModel subAreaDmModel : subAreaTerminal) {
				String termBrandUsers = subAreaDmModel.getTermBrandUsers();
				stringList.add(termBrandUsers);
			}
		}else{
			List<AreaDmModel> areaTerminal = areaDmMapper.selectAreaTerminal(mytimeType);
			for (AreaDmModel areaDmModel : areaTerminal) {
				String termBrandUsers = areaDmModel.getTermBrandUsers();
				stringList.add(termBrandUsers);
			}
		}
		splitToMap = MySplitUtilToList.splitToMap(stringList);
		List<String> mapKey  = new LinkedList<>();
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
			String key = entry.getKey();
			mapKey.add(key);
		}
		
		Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();  
		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
	    	String key = entry.getKey();
			List<Integer> value = entry.getValue();
			Integer sum = 0;
			for (Integer integer : value) {
				sum = sum + integer;
			}
			sortedMap.put(key, sum);
		}   
	    Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String,Integer>>() {
	        @Override
	        public int compare(Entry<String, Integer> o1,
	                Entry<String, Integer> o2) {
	            return o2.getValue()-o1.getValue();
	        }
	    };
	    
	    // map转换成list进行排序
	    //将排序后的map中的key值取出放入list（sortedMapKey）中
	    List<Map.Entry<String, Integer>> listMap = new ArrayList<Map.Entry<String,Integer>>(sortedMap.entrySet());
	    Collections.sort(listMap,valueComparator);
	    int i=0;
	    for (Map.Entry<String, Integer> entry : listMap) {
	    	String key = entry.getKey();
	    	Integer value = entry.getValue();
	    	sumListTerminal.add(value);
			terminalList.add(key);
//			i++;
//			if(i==20){
//				break;
//			}
	    } 
	    for(int j=0;j<sumListTerminal.size();j++){
			Object[] objs = new Object[rowsName.length];
			objs[0] = areaName;
			objs[1] = exportTime;
			objs[2] = terminalList.get(j);
			objs[3] = sumListTerminal.get(j);
			dataList.add(objs);
		}
	    ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }
	
	/**
	 * 月消费分布导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param upTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月6日
	 */
	@RequestMapping(value = "/monthlyConsumptionExport")
    @ResponseBody
    public void consumptionPoupation(String beginTime,String upTime,String areaId,String subAreaId,String areaname,HttpServletRequest request,HttpServletResponse response) {
    	if(ToolUtil.isEmpty(areaId)||ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(upTime)) {
    		return;
    	}
    	String[] rowsName = new String[] { "区域", "时间", "消费(元)", "客流(人)"};
		List<Object[]> dataList = new ArrayList<Object[]>();
		String fileName = "月消费分布";
		String areaName = areaname;
		String exportTime = beginTime + "-" + upTime;
    	MyTimeType mytimeType = new MyTimeType();
    	mytimeType.setAreaId(areaId);
    	mytimeType.setSubAreaId(subAreaId);
    	List<String> stringList = new ArrayList<String>();//月消费额度解析集合
    	List<String> consumptionList = new ArrayList<String>();//月消费额度集合
    	Map<String, List<Integer>> splitToMap = new LinkedHashMap<>();
    	List<Integer> sumListConsumption = new ArrayList<Integer>();//求和后的list
    	if(ToolUtil.isNotEmpty(subAreaId)){
			List<SubAreaDmModel> subAreaConsumption = subAreaDmMapper.selectSubAreaConsumption(mytimeType);
			for (SubAreaDmModel subAreaDmModel : subAreaConsumption) {
				String arpuUsers = subAreaDmModel.getArpuUsers();
				stringList.add(arpuUsers);
			}
		}else{
			List<AreaDmModel> areaConsumption = areaDmMapper.selectAreaConsumption(mytimeType);
			for (AreaDmModel areaDmModel : areaConsumption) {
				String arpuUsers = areaDmModel.getArpuUsers();
				stringList.add(arpuUsers);
			}
		}
		splitToMap = MySplitUtilToList.splitToMap(stringList);
    		//对拆分后的map集合进行排序以及求和
    		//取出splitToMap中的key值（消费分布：0-10；10-20……），放入mapkey中
    		List<String> mapKey  = new LinkedList<>();
    		for (Entry<String, List<Integer>> entry : splitToMap.entrySet()) {  
    			String key = entry.getKey();
    			mapKey.add(key);
    		}
        	//构造消费水平分布map，根据value进行排序
        	Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();  
    		for(int i=0;i<mapKey.size();i++){
    			String string = mapKey.get(i);
    			int indexOf = string.indexOf("-");
    			String substringStr = string.substring(indexOf+1,string.length());
    			if("300+".equals(string)){
    				substringStr = "300";
    			}
    			sortedMap.put(string, Integer.parseInt(substringStr));
    		}
    		Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String,Integer>>() {
 		        @Override
 		        public int compare(Entry<String, Integer> o1,
 		                Entry<String, Integer> o2) {
 		            return o1.getValue()-o2.getValue();
 		        }
 		    };
 		    
 		    // map转换成list进行排序
 		    //将排序后的map中的key值取出放入list（sortedMapKey）中
 		    List<Map.Entry<String, Integer>> listMap = new ArrayList<Map.Entry<String,Integer>>(sortedMap.entrySet());
 		    Collections.sort(listMap,valueComparator);
 		    List<String> sortedMapKey  = new LinkedList<>();
 		    for (Map.Entry<String, Integer> entry : listMap) {
		        String key = entry.getKey();
		        sortedMapKey.add(key);
		    }
    		//根据list（sortedMapKey）中的值，去splitToMap中取对应key值的value进行求和计算
        	for(int j=0;j<sortedMapKey.size();j++){
        		String key = sortedMapKey.get(j);
        		List<Integer> value = splitToMap.get(key);
        		Integer sum = 0;
    			for (Integer integer : value) {
    				sum = sum + integer;
    			}
    			sumListConsumption.add(sum);
    	    	consumptionList.add(key);
        	}
        	for(int j=0;j<consumptionList.size();j++){
    			Object[] objs = new Object[rowsName.length];
    			objs[0] = areaName;
    			objs[1] = exportTime;
    			objs[2] = consumptionList.get(j);
    			objs[3] = sumListConsumption.get(j);
    			dataList.add(objs);
    		}
    	    ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	} 
	
	/**
	 * 子区域平均逗留时长导出
	 * @Description: TODO
	 * @param @param beginTime
	 * @param @param areaId
	 * @param @param subAreaId
	 * @param @param timeType
	 * @param @return   
	 * @return Object  
	 * @throws
	 * @author zhangyaoyao
	 * @date 2018年3月15日
	 */
	 @RequestMapping(value = "/staySituationRankingExport")
     @ResponseBody
	 public void staySituationRanking(String beginTime,String areaId,String subAreaId,String timeType,HttpServletRequest request,HttpServletResponse response) {
	    	if(ToolUtil.isEmpty(beginTime)||ToolUtil.isEmpty(timeType)) {
	    		return;
	    	}
	    	List<String> subAreaName = new ArrayList<String>();//子区域
	    	List<String> stayAvgTime = new ArrayList<String>();//子区域平均逗留时间
	    	MyTimeType mytimeType = new MyTimeType();
	    	Map<String,String> stayAvgMap = new HashMap<String,String>();//子区域平均逗留时间
	    	Map<String,Double> stayHourMap = new HashMap<String,Double>();//逗留情况时间粒度
	    	if(timeType.equals("小时")){
	    		stayHourMap.put("0-2",1.0);
	            stayHourMap.put("2-4",3.0);
	            stayHourMap.put("4-6",5.0);
	            stayHourMap.put("6-8",7.0);
	            stayHourMap.put("8-10",9.0);
	            stayHourMap.put("10-12",11.0);
	            stayHourMap.put("12+",12.0);
	    	}else{
	    		stayHourMap.put("0-5",2.5);
	        	stayHourMap.put("5-10",7.5);
	        	stayHourMap.put("10-15",12.5);
	        	stayHourMap.put("15-20",17.5);
	        	stayHourMap.put("20-25",22.5);
	        	stayHourMap.put("25+",25.0);
	    	}
	    	List<Map.Entry<String, Double>> compareStayHourMap = (List<Entry<String, Double>>) stayHourMap  
	                .entrySet()  
	                .stream()  
	                .sorted(Map.Entry.comparingByValue())  
	                .collect(Collectors.toList());
	    	String[] rowsName = new String[] { "区域", "时间", "子区域", "平均逗留时长"};
			List<Object[]> dataList = new ArrayList<Object[]>();
			String fileName = "子区域平均逗留时长";
			String exportTime = beginTime;
	    	Wrapper<BdapArea> areaWrapper = new EntityWrapper<BdapArea>();
	    	areaWrapper.eq("ID", areaId);
	    	List<BdapArea> areaList = areaMapper.selectList(areaWrapper);
	    	String areaName = areaList.get(0).getName();
	    	List<BdapSubArea> subAreaList = new ArrayList<BdapSubArea>();
			Wrapper<BdapSubArea> subAreaWrapper = new EntityWrapper<BdapSubArea>();
			subAreaWrapper.eq("pid", areaId);
			subAreaList = subareaMapper.selectList(subAreaWrapper);
	    		if(StringUtils.isNotEmpty(beginTime)){
	    			mytimeType.setBeginTime(beginTime);
	    			for (int i=0;i<subAreaList.size();i++) {
	    				List<String> stringList = new ArrayList<String>();//逗留情况解析集合
	    				BdapSubArea bdapSubArea = subAreaList.get(i);
	    				String name = bdapSubArea.getName();
	    				Long rankingSubAreaId = bdapSubArea.getId();
	    				Long rankingId = bdapSubArea.getPid();
	    				mytimeType.setAreaId(String.valueOf(rankingId));
	    		    	mytimeType.setSubAreaId(String.valueOf(rankingSubAreaId));
	    		    	if (timeType.equals("天")) {
	    					mytimeType.setBeginTime(beginTime);
	    					if (ToolUtil.isNotEmpty(subAreaId)) {
	    						List<BdapSubareaStayMm> subAreaStayMM = subAreaStayMmMapper.selectSubAreaStayMM(mytimeType);
	    						for (BdapSubareaStayMm bdapSubareaStayMm : subAreaStayMM) {
	    							String stayTimeUsers = bdapSubareaStayMm.getStayTimeUsers();
	    							stringList.add(stayTimeUsers);
	    						}
	    					}else{
	    						List<BdapAreaStayMm> areaStayMM = areaStayMmMapper.selectAreaStayMM(mytimeType);
	    						for (BdapAreaStayMm bdapAreaStayMm : areaStayMM) {
	    							String stayTimeUsers = bdapAreaStayMm.getStayTimeUsers();
	    							stringList.add(stayTimeUsers);
	    						}
	    					}
	    				}
	    				if (timeType.equals("小时")) {
	    					mytimeType.setBeginTime(beginTime);
	    					if (ToolUtil.isNotEmpty(subAreaId)) {
	    						List<BdapSubareaPopPropDm> selectStaySituationDm = subAreaDmMapper.selectStaySituationDm(mytimeType);
	    						for (BdapSubareaPopPropDm bdapSubareaPopPropDm : selectStaySituationDm) {
	    							String stayTimeUsers = bdapSubareaPopPropDm.getStayTimeUsers();
	    							stringList.add(stayTimeUsers);
	    						}
	    					}else{
	    						List<BdapAreaPopPropDm> selectAreaStaySituationDm = areaDmMapper.selectAreaStaySituationDm(mytimeType);
	    						for (BdapAreaPopPropDm bdapAreaPopPropDm : selectAreaStaySituationDm) {
	    							String stayTimeUsers = bdapAreaPopPropDm.getStayTimeUsers();
	    							stringList.add(stayTimeUsers);
	    						}
	    					}
	    				}
	    		    	Map<String, List<Integer>> splitToMap = MySplitUtilToList.splitToMap(stringList);
	    		    	for (String key : stayHourMap.keySet()) { 
	    		    		if(splitToMap.containsKey(key)){
	    		    			continue;
	    		    		}else{
	    		    			List<Integer> list = new ArrayList<Integer>();
	    		    			list.add(0);
	    		    			splitToMap.put(key, list);
	    		    		}
	    		    	}
	    		    	Double sumTimeValue = 0d;
	    		    	Double sumValue = 0d;
	    		    	for (Entry<String, Double> entry : compareStayHourMap) {
	    		    		String key = entry.getKey();
	    		    		Double stayHourValue = entry.getValue();
	    		    		List<Integer> value = splitToMap.get(key);
	    		    		Integer sum = 0;
	    					for (Integer integer : value) {
	    						sum = sum + integer;
	    					}
	    					sumTimeValue = stayHourValue*sum+sumTimeValue;
	    					sumValue = sumValue + sum;
	    				}
	    		    	String avgStayTime = null;
	    		    	DecimalFormat df=new DecimalFormat("0.0");
	    		    	if(sumValue!=0){
	    		    		avgStayTime = df.format((double)sumTimeValue/sumValue);
	    		    		stayAvgMap.put(name, avgStayTime);
	    		    	}
	    		    	if(stayAvgMap.size()==0){
	    		    		return;
	    		    	};
	    			}
	    			 List<Map.Entry<String, String>> compareByValue = (List<Entry<String, String>>) stayAvgMap  
	    		                .entrySet()  
	    		                .stream()  
	    		                .sorted(Map.Entry.comparingByValue())  
	    		                .collect(Collectors.toList());
	    			 for (Entry<String, String> entry : compareByValue) {
	    				 subAreaName.add(entry.getKey());
	    				 stayAvgTime.add(entry.getValue());
					}
	    		}
	    		for(int k=0;k<subAreaName.size();k++){
			    	Object[] objs = new Object[rowsName.length];
					objs[0] = areaName;
					objs[1] = exportTime;
					objs[2] = subAreaName.get(k);
					objs[3] = stayAvgTime.get(k);
					dataList.add(objs);
				}
				ExcleExportUtil.exportExcel(request, response, fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
	    }
	
}
